package com.nbsaas.boot.product.rest.convert;

import com.nbsaas.boot.product.data.entity.Product;
import com.nbsaas.boot.product.api.domain.request.ProductRequest;

import org.springframework.beans.BeanUtils;
import com.nbsaas.boot.rest.api.Converter;
import com.nbsaas.boot.utils.BeanDataUtils;
            import com.nbsaas.boot.product.data.entity.ProductCatalog;
            import com.nbsaas.boot.product.data.entity.Brand;
            import com.nbsaas.boot.product.data.entity.Unit;

/**
* 商品请求对象转换成实体对象
*/

public class ProductEntityConvert  implements Converter<Product, ProductRequest> {

    @Override
    public Product convert(ProductRequest source) {
        Product result = new Product();
        BeanDataUtils.copyProperties(source, result);
                    if(source.getProductCatalog()!=null){
                    ProductCatalog productCatalog =new ProductCatalog();
                    productCatalog.setId(source.getProductCatalog());
                    result.setProductCatalog(productCatalog);
                    }
                    if(source.getBrand()!=null){
                    Brand brand =new Brand();
                    brand.setId(source.getBrand());
                    result.setBrand(brand);
                    }
                    if(source.getUnit()!=null){
                    Unit unit =new Unit();
                    unit.setId(source.getUnit());
                    result.setUnit(unit);
                    }
        return result;
    }
}

